import os  # 导入模块


def delete_files():  # 定义函数名称
    a = 0
    for i in range(31, 65):
        dir = 'train\\%s\\' % i
        for root, dirs, files in os.walk(dir):
            for filename in files:
                if int(filename[0:len(filename) - 4]) > 6000:
                    os.remove(os.path.join(root, filename))  # 删除符合条件的文件
                    print("{} deleted.".format(filename))  ##输出提示
                    a = a + 1
    print("all: " + str(a))


if __name__ == '__main__':
    path = r'train'  # 运行程序前，记得修改主文件夹路径！
    delete_files()  # 调用定义的函数，注意名称与定义的函数名一致
